package middlewares

import (
	"errors"

	"github.com/gin-gonic/gin"

	"github.com/runningwater/gohub/pkg/response"
)

// ForceUA 强制设置UA， 请求必须附带 User-Agent 标志头
func ForceUA() gin.HandlerFunc {
	return func(c *gin.Context) {
		if c.Request.Header.Get("User-Agent") == "" {
			response.BadRequest(c, errors.New("User-Agent is required"), "请求必须附带 User-Agent 标志头")
			return
		}

		c.Next()
	}
}
